package com.hkw.servlet;

import com.hkw.model.ClassRoom;
import com.hkw.model.Student;
import com.hkw.service.IClassRoomService;
import com.hkw.service.IStudentService;
import com.hkw.service.impl.ClassRoomServiceImpl;
import com.hkw.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "AddClassRoomServlet",urlPatterns = "/addClassRoom")
public class AddClassRoomServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String name = request.getParameter("classname");
        String grade = request.getParameter("grade");
        String classTeaName = request.getParameter("classTeaName");
        String slogan = request.getParameter("slogan" );
        //将获取到的值，classRoom
        ClassRoom classRoom = new ClassRoom(name,grade,classTeaName,slogan);
        System.out.println(classRoom);
        IClassRoomService classRoomService = new ClassRoomServiceImpl();
        //调用接口服务，将生成的student传入
        int update = classRoomService.add(classRoom);
        if(update==1){
            System.out.println(" 添加成功");
        }else{
            System.out.println("添加失败");
        }
        //重定向
        response.sendRedirect("classRoomList");
        System.out.println(classTeaName);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
